package com.shine.controller;

import com.shine.info.RoleInfo;
import com.shine.request.RoleCreateRequest;
import com.shine.request.RoleUpdateRequest;
import com.shine.service.RoleService;
import com.shine.utils.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author huihui
 * @date 2025/10/16 14:51
 * @description RoleController
 */
@Slf4j
@Tag(name = "角色 Controller", description = "角色 Controller")
@RestController
@RequestMapping("/role")
public class RoleController extends BaseController {

    @Resource
    private RoleService roleService;

    @GetMapping("/list")
    @Operation(summary = "角色分页查询")
    public Result<List<RoleInfo>> listRole() {
        return success(roleService.listRole());
    }

    @GetMapping("/delete/{id}")
    @Operation(summary = "根据ID删除菜单")
    public Result<Boolean> deleteRoleById(@PathVariable("id") Long id) {
        Boolean flag = roleService.deleteById(id);
        return success(flag);
    }

    @PostMapping("/update")
    @Operation(summary = "修改菜单")
    public Result<Boolean> updateRole(@RequestBody RoleUpdateRequest request) {
        Boolean flag = roleService.updateRole(request);
        return success(flag);
    }

    @PostMapping("/save")
    @Operation(summary = "新增菜单")
    public Result<Boolean> saveRole(@RequestBody RoleCreateRequest request) {
        Boolean flag = roleService.saveRole(request);
        return success(flag);
    }

}